define(function(require, exports, module) {
	J = jQuery;
	require('layer');
	layer.config({
	    path: '/assets/vendors/layer/' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
	});
	var timenow = new Date().getTime();
	
	$("#email-save-btn").on("click", function(){
		var username=$("#email").val();
		var password=$("#password").val();
		var subscribe=$("#subscribe").val();
		if(username.length>0){
			if(!/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(username)){
				$("#email").closest('div').removeClass('has-success').addClass('has-error');
				$("#email_txt").html("<span class=\"text-danger\">用户名必须为邮箱地址</span>");
				$("#email").focus();
				return false; 
			}
		}else{
			$("#email_txt").html("<span class=\"text-danger\">用户名不能为空</span>");
			$("#email").closest('div').removeClass('has-success').addClass('has-error');
			$("#email").focus();
			return false; 
		}
		
		if(password.length>=6){
			if(!/^[0-9a-zA-Z_~!@#$%^&*()_+]{6,20}$/.test(password)){
				$("#password").closest('div').removeClass('has-success').addClass('has-error');
				$("#password_txt").html("<span class=\"text-danger\">密码不能包含特殊字符货空格</span>");
				$("#password").focus();
				return false; 
			}
		}else{
			$("#password_txt").html("<span class=\"text-danger\">密码必须是6-20位字符</span>");
			$("#password").closest('div').removeClass('has-success').addClass('has-error');
			$("#password").focus();
			return false;
		}

		$.ajax({
    		url: '/member/email.json', 
    		data: {'username': username,'password': password,'subscribe': subscribe},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('发送错误', {icon: 2});
    		},
    		success: function(data){	
    			if(data.result){
    				window.location.reload();
    				return false;
    			}else{
					if(data.errors.password!=''){
						layer.msg(data.errors.password, {icon: 2});
						return false;
					}else if(data.errors.username!=''){
						layer.msg(data.errors.username, {icon: 2});
						return false;
					}
				}
          	}
    	});
	});
});